<?
include '../includes/specs_functions.php';

#----------------------------------------------------
# Connect to PADS
$DB = getDB();

$jobId = $_POST['jobId'];
$lvl = $_POST['lvl'];

$level = 50; // Max level ignore all other skills

	$table = "(".SPEC_TBL_TEMPLATES." as temp
			LEFT JOIN 
			".TBL_ABILITIES." as ab
			ON ab.".TBL_ABILITIES_ID." = temp.".SPEC_TBL_TEMPLATES_SKILL_ID.")";
	$col = array(
			"ab.".TBL_ABILITIES_ENNAME." as name"
			,"ab.".TBL_ABILITIES_LEVEL." as level"
			,"ab.".TBL_ABILITIES_ID." as id"
			,"ab.".TBL_ABILITIES_MP." as mp"
			,"ab.".TBL_ABILITIES_HP." as hp"
			,"ab.".TBL_ABILITIES_TP." as tp"
			,"ab.".TBL_ABILITIES_CASTTIME." as cast"
			,"ab.".TBL_ABILITIES_RECASTTIME." as recast"
			,"ab.".TBL_ABILITIES_RANGE." as range"
			,"ab.".TBL_ABILITIES_ICON." as icon"
			,"ab.".TBL_ABILITIES_ENDESC." as description"
			);

		   
	$where = array(
				"temp.".SPEC_TBL_TEMPLATES_JOB_ID." = \"".$jobId."\""
				,"ab.".TBL_ABILITIES_LEVEL." <= \"".$lvl."\""
				);
	$orderBy = "ab.".TBL_ABILITIES_LEVEL;
	$direction = "ASC";
	
	
	$result = $DB->GetData($table ,$col ,true ,$where, $orderBy, $direction);
	//Show($result);
	
	//Show($result);
	
	$jobs = array();
	
	foreach ($result[3] as $row) {
			
		$job = array( 
						"id" => $row['id']
						,"name" => $row['name']
						,"level" => $row['level']
						,"mp" => $row['mp']
						,"hp" => $row['hp']
						,"tp" => $row['tp']
						,"cast" => $row['cast']
						,"recast" => $row['recast']
						,"range" => $row['range']
						,"icon" => $row['icon']
						,"desc" => $row['description']
						,"type" => "skill"
					);
		array_push($jobs, $job);
	}
	
echo json_encode($jobs);
	
#------------------------------------------------------------------------
# Disconnect
leaveDB($DB);


?>